package com.sgb.kjwl.viewmodel.transport;

import androidx.databinding.ObservableField;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.transport.GoodsInfoDetailEntity3;
import com.sgb.kjwl.repository.TransportRepertory;
import com.sgb.kjwl.view.ui.activity.transport.GoodsInfoDetailActivity3;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class GoodsInfoDetailModel3 extends BaseViewModel {

    private GoodsInfoDetailActivity3 activity;
    private TransportRepertory repertory;
    public ObservableField<GoodsInfoDetailEntity3> detailEntity = new ObservableField<>(new GoodsInfoDetailEntity3());

    public GoodsInfoDetailModel3(GoodsInfoDetailActivity3 activity3, TransportRepertory repertory){
        this.activity = activity3;
        this.repertory = repertory;
    }

    public void getGoodsInfoDetail(String id){

        DialogHelper.showProgressDialog(activity, null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getDriverAPI().getGoodsSourceDetail(repertory.getAreaCode(),id).enqueue(new Callback<BaseEntity<GoodsInfoDetailEntity3>>() {
            @Override
            public void onResponse(Call<BaseEntity<GoodsInfoDetailEntity3>> call, Response<BaseEntity<GoodsInfoDetailEntity3>> response) {
                DialogHelper.dismissProgressDialog();

                if (response.body() == null) return;

                if (response.body().getState().equals("ok")) {
                    detailEntity.set(response.body().getData());
                    activity.getGoodsInfoDetail(response.body().getData());
                }
            }
            @Override
            public void onFailure(Call<BaseEntity<GoodsInfoDetailEntity3>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }
}
